﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace LGE
{
    public static class Tile
    {
        public static int Size = 30;
        public static Dictionary<int, Texture2D> Textures = new Dictionary<int, Texture2D>();
        public static int UndergroundCode = 0;
        public static int frameInterval = 40; // em ms
        
        public static void Initialize(int size, String tilesFolder)
        {
            Size = size;
            for (int i = 0; i < 100; ++i)
            {
                try { Textures.Add(i, Engine.Load<Texture2D>(tilesFolder + "\\" + i.ToString())); }
                catch { continue; }
            }
        }

        public static void Draw(SpriteBatch spriteBatch, GameTime gameTime, int code, Vector2 pos)
        {
            int i = (int)((gameTime.TotalGameTime.TotalMilliseconds / frameInterval) % (Textures[code].Width / Tile.Size));
            spriteBatch.Draw(Textures[code], pos, new Rectangle(i * Tile.Size, 0, (i + 1) * Tile.Size, Tile.Size), Color.White);
        }
    }
}
